#include "PcmBufferSpan.h"


PcmBufferSpan::PcmBufferSpan() : buffer(nullptr), lengthInBytes(-1), consumedBytes(0) {
}

PcmBufferSpan::PcmBufferSpan(PcmBufferSpan &&that) {
    this->buffer = std::move(that.buffer);
    this->lengthInBytes = that.lengthInBytes;
    this->consumedBytes = that.consumedBytes;
    that.lengthInBytes = -1;
}

PcmBufferSpan &PcmBufferSpan::operator=(PcmBufferSpan &&that) {
    this->buffer = std::move(that.buffer);
    this->lengthInBytes = that.lengthInBytes;
    this->consumedBytes = that.consumedBytes;
    that.lengthInBytes = -1;
    return *this;
}

PcmBufferSpan::sample_t *PcmBufferSpan::currentData() const {
    if (!buffer || lengthInBytes <= 0) {
        return nullptr;
    }
    return reinterpret_cast<sample_t*>(reinterpret_cast<uint8_t*>(buffer.get()) + consumedBytes);
}

int64_t PcmBufferSpan::remainingBytes() const {
    return lengthInBytes - consumedBytes;
}

void PcmBufferSpan::advanceBytes(int64_t length) {
    consumedBytes += length;
}
